#!/bin/sh 
# 
# php-cgi Startup script for the php-cgi server 
# 
# chkconfig: - 85 15 
# description: fast cgi server for php 
# 
# processname: php-cgi 
# config: /etc/php.ini 
# pidfile: /var/run/php-cgi.pid 
# 
# Note: pidfile is assumed to be created 
# by php-cgi (config: server.pid-file). 
# If not, uncomment 'pidof' line. 

# Source function library 
. /etc/rc.d/init.d/functions 

if [ -f /etc/sysconfig/php-cgi ]; then 
        . /etc/sysconfig/php-cgi 
fi 

prog="php-cgi" 
#FCGIPHP=/opt/install/php/bin/php-cgi 
#FCGIPHP=/opt/install/php/bin/php 
FCGIPHP=/usr/bin/php-cgi 
#FCGIPHPCONF="/opt/php.ini-development"
FCGIPHPCONF="/opt/php.ini"



FCGIPORT="9000" 
FCGIADDR="127.0.0.1" 
FCGIUSER="website" 
PHP_FCGI_CHILDREN=10 
PHP_FCGI_MAX_REQUESTS=50 
export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS 

RETVAL=0 

start() { 
        echo -n $"Starting $prog: " 
 daemon --user $FCGIUSER "export PHP_FCGI_CHILDREN=5; export PHP_FCGI_MAX_REQUESTS=1000; $FCGIPHP -b $FCGIADDR:9000  -c $FCGIPHPCONF  &" 
 daemon --user $FCGIUSER "export PHP_FCGI_CHILDREN=5; export PHP_FCGI_MAX_REQUESTS=1000; $FCGIPHP -b $FCGIADDR:9001  -c $FCGIPHPCONF  &" 

#spawn-fcgi -a 127.0.0.1 -p 9000 -C 300 -u website -f /usr/bin/php-cgi
#spawn-fcgi -a 127.0.0.1 -p 9001 -C 300 -u website -f /usr/bin/php-cgi
#spawn-fcgi -a 127.0.0.1 -p 9002 -C 300 -u website -f /usr/bin/php-cgi
        RETVAL=$? 
        echo 
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog 
        return $RETVAL 
} 

stop() { 
        echo -n $"Stopping $prog: " 
        killproc $FCGIPHP 
        RETVAL=$? 
        echo 
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog 
        return $RETVAL 
} 

reload() { 
        echo -n $"Reloading $prog: " 
        killproc $FCGIPHP -HUP 
        RETVAL=$? 
        echo 
        return $RETVAL 
} 

case "$1" in 
        start) 
                start 
                ;; 
        stop) 
                stop 
                ;; 
        restart) 
                stop 
                start 
                ;; 
        condrestart) 
                if [ -f /var/lock/subsys/$prog ]; then 
                        stop 
                        start 
                fi 
                ;; 
        reload) 
                reload 
                ;; 
        status) 
                status $FCGIPHP 
                RETVAL=$? 
                ;; 
        *) 
                echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}" 
                RETVAL=1 
esac 

exit $RETVAL

